#!/usr/bin/php
<?php

set_time_limit (0);

$host = "localhost";
$port = "22122";

function dbug ($str) { echo $str, "\n"; }

$erf = 0;
while ($erf < 1)
	{
	$erf ++;

if (($socket = @socket_create (AF_INET, SOCK_STREAM, 0)) === false)
	die ("Impossible de creer la socket client\n");

if (@socket_connect ($socket, $host, $port) === false)
		die ("Impossible de se connecter au client\n");

$data;
for ($i = 0; $i < 5000; $i++)
	$data.= 'c';
$data_size = strlen ($data);


$_ARGV = $_SERVER['argv'];

if ($_ARGV[1] == 'add' || $_ARGV[1] == 'set')
	{
		if (sizeof ($_ARGV) != 4)
			die ("USAGE : {$_ARGV[0]} add <key> <data>\n");

		$json = json_encode (array ('command' => $_ARGV[1],
																'key' => sha1 ($_ARGV[2]),
																'data' => $_ARGV[3],
																'size' => strlen ($_ARGV[3]),
																'expire' => 60));
		dbug ($json);		

	}
elseif ($_ARGV[1] == 'get' || $_ARGV[1] == 'del')
  {
		if (sizeof ($_ARGV) != 3)
			die ("USAGE : {$_ARGV[0]} get <key>\n");

		$json = json_encode (array ('command' => $_ARGV[1],
																'key' => sha1 ($_ARGV[2])));
		
		dbug ($json);		
	}


		socket_write ($socket, $json);
		sleep (1);
	}


	





